package fms.models;
 
import java.util.List;
 
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import fms.classes.Form9;
 
 
public class Form9DAO {
 
    private SqlSessionFactory sqlSessionFactory;
 
    public Form9DAO(){
    	try{
    		sqlSessionFactory = MyBatisSqlConnection.getSqlSessionFactory();
    	}catch(Exception e) {
    		System.out.println("failed to get sqlSessionFactory");
    	}
    }
 
    /**Returns the list of all Form9 instances from the database*/
    @SuppressWarnings("unchecked")
    public List<Form9> selectAll(){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            List<Form9> list = session.selectList("Form9.getAll");
            return list;
        } finally {
            session.close();
        }
    }
 
    /**Returns a Form9 instance from the database*/
    public Form9 selectById(int payroll_no){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            Form9 form9 = (Form9) session.selectOne("Form9.getById", payroll_no);
            return form9;
        } finally {
            session.close();
        }
    }
 
    /**Returns a Form9 instance from the database
    public Form9 getAllPending(String status){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            Form9 form9 = (Form9) session.selectOne("Form9.getAllPending", status);
            return form9;
        } finally {
            session.close();
        }
    }*/
    
    /**Updates an instance of Form9 in the database*/
    public void update(Form9 form9){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            session.update("Form9.update", form9);
            session.commit();
        } finally {
            session.close();
        }
    }
    
    /**Updates the status of Form9 in the database
    public void updateStatus(int payroll_no){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            session.update("Form9.updateStatus", payroll_no);
            session.commit();
        } finally {
            session.close();
        }
    }*/
 
    /** Insert an instance of Form9 into the database*/
    public void insert(Form9 form9){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            session.insert("Form9.insert", form9);
            session.commit();
        } finally {
            session.close();
        }
    }
 
    /** Delete an instance of Form9 from the database*/
    public void delete(int payroll_no){
 
        SqlSession session = sqlSessionFactory.openSession();
 
        try {
            session.delete("Form9.deleteById", payroll_no);
            session.commit();
        } finally {
            session.close();
        }
    }
}